package com.slipper.collect.support;

import com.slipper.collect.IDataConvert;

import java.time.ZoneId;

public class DateToMillsDataConvert implements IDataConvert {
    @Override
    public Object convert(String param, Object data) {
        if (data == null) return null;

        return switch (data) {
            case java.sql.Time date -> date.getTime();
            case java.sql.Date date -> date.getTime();
            case java.sql.Timestamp date -> date.getTime();
            case java.util.Date date -> date.getTime();
            case java.time.LocalDate date -> date.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant().getEpochSecond() * 1000;
            case java.time.LocalTime date -> (long) date.getSecond() * 1000;
            case java.time.LocalDateTime date -> date.atZone(ZoneId.systemDefault()).toInstant().getEpochSecond() * 1000;
            default -> null;
        };
    }
}
